//
//  XZNewsCaseKeyCell.m
//  Teecloud
//
//  Created by PC on 2018/10/19.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZNewsCaseKeyCell.h"
#import "XZNewsCase.h"
@implementation XZNewsCaseKeyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)setModel:(XZNewsCase *)model{
    _model = model;
    
    //间距
    CGFloat padding =10;
    
    CGFloat titBtnX =10;
    
    CGFloat titBtnY =10;
    
    CGFloat titBtnH =30;
    
    for(int i =0; i <model.KeyList.count; i++){
        
        UIButton *titBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        //设置按钮的样式
        titBtn.backgroundColor= kEFEFEFColor;
        
        [titBtn setTitleColor:kDarkGrayColor forState:UIControlStateNormal];
        
        titBtn.titleLabel.font= [UIFont systemFontOfSize:13];
        
        [titBtn setTitle:[NSString stringWithFormat:@"%@",model.KeyList[i]] forState:UIControlStateNormal];
        
        titBtn.tag=1000+i;
        
        [titBtn addTarget:self action:@selector(titBtnClike:) forControlEvents:UIControlEventTouchUpInside];
        
        //计算文字大小
        CGSize titleSize = [model.KeyList[i] boundingRectWithSize:CGSizeMake(MAXFLOAT, titBtnH) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.titleLabel.font} context:nil].size;
        //按钮的宽
        CGFloat titBtnW = titleSize.width+2* padding;
        //设置按钮的位置
        titBtn.frame=CGRectMake(titBtnX, titBtnY, titBtnW, titBtnH);
        
        titBtnX += titBtnW + padding;
        
        [self.contentView addSubview:titBtn];
        
    }
}
- (void)titBtnClike:(UIButton *)sender{
    if (self.KeyButtonBlock) {
        self.KeyButtonBlock(sender.titleLabel.text);
    }
}

@end
